import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { NavParams, Events, ModalController } from '@ionic/angular';

@Component({
    selector: 'type-select',
    templateUrl: 'type-select.html',
    styleUrls: ['type-select.scss']
})
export class TypeSelectModal implements OnInit {
    type;
    backup;
    title;
    default;

    constructor(public navParams: NavParams, public events: Events, public modalCtrl: ModalController) {
    }

    ngOnInit() {
        this.type = 'radio';
        this.backup = [{ name: 2400 }, { name: 4800 }, { name: 9600 }];
        this.title = this.navParams.get('title');
        this.default = this.navParams.get('value');
        console.log(this.default);
        for (let i = 0; i < this.backup.length; i++) {
            if (this.default) {
                if (this.default === this.backup[i].name) {
                    this.backup[i].checked = true;
                }
            }
        }
    }

    setRadio(e, i) {
        if (this.type === 'radio') {
            for (let j = 0; j < this.backup.length; j++) {
                if (j === i) {
                    this.backup[j].checked = true;
                } else {
                    this.backup[j].checked = false;
                }
            }
        }
        this.closeModel(e.name);
    }

    // 关闭模型
    closeModel(value) {
        console.log(value)
        this.modalCtrl.dismiss(value);
    }
}
